<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/ajax.js"></script>
    <script src="/html/js/layui.js"></script>
    <script src="/html/js/util.js"></script>
    <link rel="stylesheet" href="/html/js/css/layui.css" media="all">
    <title>添加订单</title>
    <style>
        .errorInfo {
            color: red;
        }
    </style>

</head>
<script>
    let orderPrice = 0;
    window.onload = function () {
        orderPrice = getQuery("totalPrice");
    }

    async function addNewOrder() {
        let param = {
            orderPeo: $("orderPeo").value,
            orderLocation: $("orderLocation").value,
            orderTel: $("orderTel").value,
            orderAllPrice: orderPrice
        }
        let result = await ajaxGet("/order/add", param);
        if (result == "ok") {
            location.href = "/html/custom/success.html";
        } else {
            let arrays = document.getElementsByClassName("errorInfo");
            for (let i = 0; i < arrays.length; i++) {
                arrays[i].innerHTML = "";
            }

            for (let i = 0; i < result.length; i++) {
                let objError = result[i];
                console.log(objError);
                $(objError.field + "Div").innerHTML = objError.defaultMessage;
            }
        }
    }
</script>


<body style="padding-top: 50px">
<div style="padding:0 30px;display: flex;justify-content: center">

    <div>
        <h3>完善订单信息</h3>
        <br>
        <div id="orderPeoDiv" class="errorInfo"></div>
        <label class="layui-form-label">收件人姓名</label>
        <input type="text" id="orderPeo" required lay-verify="required"
               autocomplete="off"
               class="layui-input" style="width: 200px">
        <br>
        <div id="orderLocationDiv" class="errorInfo"></div>
        <label class="layui-form-label">送货地址</label>
        <input type="text" id="orderLocation" required lay-verify="required"
               autocomplete="off"
               class="layui-input" style="width: 200px">
        <br>
        <div id="orderTelDiv" class="errorInfo"></div>
        <label class="layui-form-label">收货人电话</label>
        <input type="text" id="orderTel" required lay-verify="required"
               autocomplete="off"
               class="layui-input" style="width: 200px">
        <br>
        <button type="button" class="layui-btn" onclick="addNewOrder()">提交订单</button>
        <button type="button" class="layui-btn"><a href="/html/index.html">返回主页</a></button>
    </div>
</div>

</body>
</html>